#include "processBar.h"
#include <string.h>
#include <unistd.h>

#define GREEN "\033[0;33;32m"
#define NONE "\033[m"


const char lable[] = "|/-\\";
char bar[NUM] = {0};
void processbar(int rate)
{
    if(rate < 0 || rate > 100)
    {
        return;
    }
    int len = strlen(lable);    
    printf(GREEN"[%-100s]"NONE"[%d%%][%c]\r",bar,rate,lable[rate%len]);
    fflush(stdout);
    bar[rate++] = BODY;
    if(rate < TOP)
    {
        bar[rate] = RIGHT;
    }
}
void initbar()
{
    memset(bar,'\0',sizeof(bar));
}
/*
void processbar(int speed)
{

    int len = strlen(lable);
    char bar[NUM];
    memset(bar,'\0',sizeof(bar));
    int cnt = 0;
    while(cnt <= TOP)
    {
        printf("[%-100s][%d%%][%c]\r",bar,cnt,lable[cnt%len]);
        fflush(stdout);
        bar[cnt++] = BODY;
        if(cnt < TOP)
        {
            bar[cnt] = RIGHT;
        }
        usleep(speed);
    }
    printf("\n");
}*/
